package com.camps.sdk.decrypt;

import com.camps.sdk.common.Constants;
import com.camps.sdk.entity.DeviceUpMessage;
import com.camps.sdk.entity.Heart;
import com.camps.sdk.entity.LocationData;
import com.camps.sdk.utils.LocationUtils;

import java.util.List;

/**
 * @Author ldaoliang
 * @Date create in 15:58 2021/9/1
 * @Description
 */
public class AnalyzeLocatedHeartBeat implements AnalyticalData {
    @Override
    public DeviceUpMessage parseData(String originalData) {
        //*WT,800115470000876,V2,170652,108,0,8,0,A,2250.2261,N,11391.6159,E,0.11,356,030621,FFFFDFFF#
        //解密
        String[] split = parseCommand(originalData);
        String imei = split[1];
        String commandNumber = split[3];
        String gsm = split[4];//gsm
        String gps = split[5];//gps
        String battery = split[6];//电量
        String stepNum = split[7];  // 步数
        String lat = split[9];
        String lng = split[11];
        String speed = split[13];
        String orientation = split[14];
        String date = split[15];
        String deviceStatus = split[16];
        List<Double> list = LocationUtils.transiformLatAndLng(lng, lat);
        Heart heart = new Heart();
        heart.setImei(imei);
        heart.setCommandNumber(commandNumber);
        heart.setBattery(Integer.parseInt(battery));
        heart.setDeviceDate(date);
        heart.setDeviceTime(commandNumber);
        heart.setStepNum(Integer.parseInt(stepNum));
        heart.setDeviceStatus(deviceStatus);
        LocationData mqLocationData = new LocationData();
        mqLocationData.setOrientation(Integer.parseInt(orientation));
        mqLocationData.setSpeed(Double.parseDouble(speed));
        mqLocationData.setLatitude(list.get(1));
        mqLocationData.setLongitude(list.get(0));
        heart.setLocationData(mqLocationData);
        return structureMessage(Constants.UPLOAD,Constants.UP_LOCATED_HEARTBEAT,false,"",heart);
    }
}
